package com.aiit.util;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;

/**
 * 文件上传
 */
public class FileUploadUtil {

    /**
     * @param upload
     * @throws Exception
     */
    public static void fileUpload(MultipartFile upload) throws Exception {
        //使用fileupliad组件完成文件上传
        String path="D:\\upload";

        //判断路径是否存在
        File f=new File(path);
        if(!f.exists()){
            //不存在创建
            f.mkdirs();
        }
        System.out.println(path);

        //获取上传文件名
        String filename=upload.getOriginalFilename();
        //将名字设置唯一
        filename= UUIDFactory.getUUID() +"_"+filename;
        //上传
        upload.transferTo(new File(path,filename));

    }
}
